﻿<?php
	session_start();
	error_reporting (E_ALL ^ E_NOTICE);
	include("./config/conn_database.php");
	if($_SESSION["mem_pid"] != "" || $_SESSION["mem_pid"] != NULL){
		if($_GET['act']=="del"){
			$strSQL = "DELETE FROM add_news WHERE news_id = '".$_GET['id']."'";
			$objQuery = mysql_query($strSQL);
			echo "<meta http-equiv='refresh' content='0; url=edit_index_news.php'>";
		}else if($_GET['act']=="edit"){
			echo "<meta http-equiv='refresh' content='0; url=edit_index_news.php?id=".$_GET['id']."'>";
		}else if($_GET['act']=="edit_sql"){
			$strSQL = "UPDATE add_news SET 
						news_topic = '".$_POST['topic']."', 
						news_detail = '".$_POST['detail']."',
						news_ref = '".$_POST['ref']."',
						news_date = '".date("Ymd")."',
						mem_pid = '".$_SESSION["mem_pid"]."' 
						WHERE  news_id = '".$_GET['id']."'";
			$objQuery = mysql_query($strSQL);
			echo "<meta http-equiv='refresh' content='0; url=edit_index_news.php'>";
		}else{
			$strSQL = "INSERT INTO add_news (news_id, news_topic, news_detail, news_ref, news_date, mem_pid)
						VALUES (NULL, '".$_POST['topic']."', '".$_POST['detail']."', '".$_POST['ref']."', '".date("Ymd")."', '".$_SESSION["mem_pid"]."');";
			$objQuery = mysql_query($strSQL);
			if($objQuery){
				echo "<script type='text/javascript'>";
				echo "alert('บันทึกข้อมูลสำเร็จ')";
				echo "</script>";
				echo "<meta http-equiv='refresh' content='0; url=edit_index_news.php'>";
			}else{
				echo "<script type='text/javascript'>";
				echo "alert('บันทึกข้อมูลไม่สำเร็จ : ติดต่อผู้ดูแลระบบ')";
				echo "</script>";
				echo "<meta http-equiv='refresh' content='0; url=edit_index_news.php'>";
			}
		}
		mysql_close($objConnect);
	}else{	
		echo "<script type='text/javascript'>";
		echo "alert('กรุณาเข้าสู่ระบบก่อนเข้าใช้งาน')";
		echo "</script>";
		echo "<meta http-equiv='refresh' content='0; url=index.php'>";
	}
?>